<template>
  <div>
    <refresh ref="refresh" :upPullEvent="queryList" :upPullEnable="upPullEnable" :bottom="bottom">
      <div class="list-inner">
        <div class="live-list" v-if="dataList.length">
          <row v-for="(item, index) in dataList" :tabData="item" :key="index"></row>
        </div>
        <div v-if="noData" class="empty">暂无文章推荐</div>
      </div>
    </refresh>
  </div>
</template>

<script>
// @ is an alias to /src
import query from '@/lib/query.js';
import refresh from '@/components/common/UpLoadRefresh.vue';
import row from '@/components/live/ArticleRow.vue';
import upPullMixin from '@/lib/upPullMixin.js';
export default {
  name: 'JournalList',
  mixins: [upPullMixin],
  components: {
    refresh,
    row,
  },
  data() {
    return {
      pageLoadMsg: {},
      dataList: [],
      lock: false,
    };
  },
  props: {
    themId: {
      type: String,
      default: '',
    },
  },
  created() {
    this.$pageStatus.loading();
    this.initPage();
  },
  methods: {
    initPage() {
      this.queryList();
    },
    // 加载更多的逻辑
    queryList() {
      if (this.lock) {
        return;
      }
      this.lock = true;
      this.setPageStatus();
      const param = {
        ...this.pageLoadMsg,
      };
      query
        .getHotNews(param)
        .then(res => {
          this.$pageStatus.close();
          this.lock = false;
          if (res.data?.auth) {
            this.formatPagingData(res.data?.page);
          }
        })
        .catch(err => {
          this.lock = false;
          this.mixinErrHandler(err, this.reload);
        });
    },
    // 分页处理
    setPageStatus() {
      if (this.pageLoadMsg.page_num) {
        this.pageLoadMsg.page_num++;
      } else {
        this.pageLoadMsg = {
          page_num: 1,
          page_size: 10,
        };
      }
    },
  },
};
</script>
<style lang="less" scoped>
.live-list {
  padding: 0 0.32rem;
  .row-card {
    &:last-child {
      border-bottom: none;
    }
  }
}
.list-inner {
  background-color: #ffffff;
}
</style>
